﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Web;
using System.Threading.Tasks;
using System.Data;
using BartonExtension;
using ResponseObject;
using SQLWrapper;
using Model.App;
using Model.Images;
using Model.Weixin;
using Services.Common;
using Services.User;
using Services.Messages;

namespace iShangMai.Controllers.App
{
    public class RecvRecipController : ApiController
    {
        [HttpPost]
        public async Task<ZKResponse> DidRecvRecip(ISMRecvRecipRequest request)
        {
            ZKResponse response = new ZKResponse();
            ISMServiceModel model = new ISMServiceModel() { userinfo = request };
            ISMServiceProvider provider = null;
            switch(request.type)
            {
                case RecipType.kRecipTypeFriendReq:
                    {
                        provider = (ISMFriendServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.FRIEND];
                        model.operationIdentifier = ISMFriendServiceProvider.UPDATE_REQ_READ_TAG;
                    }
                    break;
                case RecipType.kRecipTypePrivateMessage:
                    {
                        provider = (ISMPrivateMessageServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.PRIVATE_MESSAGES];
                        model.operationIdentifier = ISMPrivateMessageServiceProvider.DID_MSG_RECVED;
                    }
                    break;
                default:
                    provider = null;
                    break;
            }
            if(provider == null)
            {
                response.isProcessSuccess = false;
                response.errMsg = "非法参数";
                return response;
            }

            ISMServiceResult result = await provider.doProcess(model);
            response.isProcessSuccess = result.isOperationSuccess;
            response.errMsg = result.errorMsg;
            response.userinfo = result.dbReturningState;
            return response;
        }
    }
}
